﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JsonConvertDemo
{
    internal class Program
    {
        static void Main(string[] args)
        {
            string jsonFilePath = @"C:\Users\13257\Desktop\a.json";
            string jsonString = File.ReadAllText(jsonFilePath);
            try
            {
                // 将JSON字符串反解析为对象
                var deserializedObject = JsonConvert.DeserializeObject<DataType>(jsonString);
                Console.WriteLine(deserializedObject.Item);
                Console.WriteLine(deserializedObject.acoustic.channels[0]);
                // 获取a.json文件中的Item字段的值 
                Console.WriteLine("Item字段的值为: " + deserializedObject.Item);
            }
            catch (JsonException ex)
            {
                Console.WriteLine("JSON解析出错: " + ex.Message);
            }

            
        }

        class DataType
        {
            public string Item { get; set; }
            public string DataPath { get; set; }

            public Acoustic acoustic { get; set; }
        }

        class Acoustic
        {
            public double sensitivity { get; set; }
            public List<string> channels { get; set; }
        }

    }
}
